<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Attach a filter to a stream</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.stream-filter-append" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stream_filter_append</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">stream_filter_append</span> &mdash; <span class="dc-title">Attach a filter to a stream</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.stream-filter-append-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>stream_filter_append</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stream</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$filtername</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$read_write</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$params</code></span>
  ]] ) : <span class="type">resource</span></div>

  <p class="para rdfs-comment">
   Adds <code class="parameter">filtername</code> to the list of filters
   attached to <code class="parameter">stream</code>.  
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.stream-filter-append-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">stream</code></dt>

     <dd>

      <p class="para">
       The target stream.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">filtername</code></dt>

     <dd>

      <p class="para">
       The filter name.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">read_write</code></dt>

     <dd>

      <p class="para">
       By default, <span class="function"><strong>stream_filter_append()</strong></span> will
       attach the filter to the <em>read filter chain</em>
       if the file was opened for reading (i.e. File Mode:
       <em>r</em>, and/or <em>+</em>).  The filter
       will also be attached to the <em>write filter chain</em>
       if the file was opened for writing (i.e. File Mode:
       <em>w</em>, <em>a</em>, and/or <em>+</em>).
       <strong><code>STREAM_FILTER_READ</code></strong>,
       <strong><code>STREAM_FILTER_WRITE</code></strong>, and/or
       <strong><code>STREAM_FILTER_ALL</code></strong> can also be passed to the
       <code class="parameter">read_write</code> parameter to override this behavior.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">params</code></dt>

     <dd>

      <p class="para">
       This filter will be added with the specified 
       <code class="parameter">params</code> to the <em class="emphasis">end</em> of
       the list and will therefore be called last during stream operations.
       To add a filter to the beginning of the list, use
       <span class="function"><a href="stream_filter_prepend.html" class="function">stream_filter_prepend()</a></span>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.stream-filter-append-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a resource on success or <strong><code>FALSE</code></strong> on failure. The resource can be
   used to refer to this filter instance during a call to
   <span class="function"><a href="stream_filter_remove.html" class="function">stream_filter_remove()</a></span>.
  </p>

  <p class="para">
   <strong><code>FALSE</code></strong> is returned if <code class="parameter">stream</code> is not a resource or
   if <code class="parameter">filtername</code> cannot be located.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.stream-filter-append-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.1.0</td>
       <td>
        Prior to PHP 5.1.0, this function returns <strong><code>TRUE</code></strong> on success
        或者在失败时返回 <strong><code>FALSE</code></strong>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.stream-filter-append-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4819">
    <p><strong>Example #1 Controlling where filters are applied</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Open&nbsp;a&nbsp;test&nbsp;file&nbsp;for&nbsp;reading&nbsp;and&nbsp;writing&nbsp;*/<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'test.txt'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'w+'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Apply&nbsp;the&nbsp;ROT13&nbsp;filter&nbsp;to&nbsp;the<br />&nbsp;*&nbsp;write&nbsp;filter&nbsp;chain,&nbsp;but&nbsp;not&nbsp;the<br />&nbsp;*&nbsp;read&nbsp;filter&nbsp;chain&nbsp;*/<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"string.rot13"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">STREAM_FILTER_WRITE</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Write&nbsp;a&nbsp;simple&nbsp;string&nbsp;to&nbsp;the&nbsp;file<br />&nbsp;*&nbsp;it&nbsp;will&nbsp;be&nbsp;ROT13&nbsp;transformed&nbsp;on&nbsp;the<br />&nbsp;*&nbsp;way&nbsp;out&nbsp;*/<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"This&nbsp;is&nbsp;a&nbsp;test\n"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Back&nbsp;up&nbsp;to&nbsp;the&nbsp;beginning&nbsp;of&nbsp;the&nbsp;file&nbsp;*/<br /></span><span style="color: #0000BB">rewind</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Read&nbsp;the&nbsp;contents&nbsp;of&nbsp;the&nbsp;file&nbsp;back&nbsp;out.<br />&nbsp;*&nbsp;Had&nbsp;the&nbsp;filter&nbsp;been&nbsp;applied&nbsp;to&nbsp;the<br />&nbsp;*&nbsp;read&nbsp;filter&nbsp;chain&nbsp;as&nbsp;well,&nbsp;we&nbsp;would&nbsp;see<br />&nbsp;*&nbsp;the&nbsp;text&nbsp;ROT13ed&nbsp;back&nbsp;to&nbsp;its&nbsp;original&nbsp;state&nbsp;*/<br /></span><span style="color: #0000BB">fpassthru</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Expected&nbsp;Output<br />&nbsp;&nbsp;&nbsp;---------------<br /><br />Guvf&nbsp;vf&nbsp;n&nbsp;grfg<br /><br />&nbsp;*/<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.stream-filter-append-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <strong>When using custom (user) filters</strong><br />
   <span class="simpara">
    <span class="function"><a href="stream_filter_register.html" class="function">stream_filter_register()</a></span> must be called first
    in order to register the desired user filter to <code class="parameter">filtername</code>.
   </span>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    Stream data is read from resources (both local and remote) in chunks,
    with any unconsumed data kept in internal buffers.  When a new
    filter is appended to a stream, data in the internal buffers is processed through
    the new filter at that time.  This differs from the behavior of
    <span class="function"><a href="stream_filter_prepend.html" class="function">stream_filter_prepend()</a></span>.
   </span>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    When a filter is added for read and write, two instances of the filter
    are created. <span class="function"><strong>stream_filter_append()</strong></span> must be called twice 
    with <strong><code>STREAM_FILTER_READ</code></strong> and 
    <strong><code>STREAM_FILTER_WRITE</code></strong> to get both filter resources.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.stream-filter-append-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="stream_filter_register.html" class="function" rel="rdfs-seeAlso">stream_filter_register()</a> - Register a user defined stream filter</span></li>
   <li class="member"><span class="function"><a href="stream_filter_prepend.html" class="function" rel="rdfs-seeAlso">stream_filter_prepend()</a> - Attach a filter to a stream</span></li>
   <li class="member"><span class="function"><a href="stream_get_filters.html" class="function" rel="rdfs-seeAlso">stream_get_filters()</a> - 获取已注册的数据流过滤器列表</span></li>
  </ul>
 </div>

</div></div></div></body></html>